//
//  MYHTTPClient.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/7/29.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

/** 
App Key：1331241592
App Secret：ff9adf9b1e3155ca93920e7f7671f53c
授权回调页：http://www.itcast.cn
取消授权回调页：http://www.itcast.cn
*/

import UIKit

enum MYHTTPClientType: String {
    
    case GET = "GET"
    case POST = "POST"
}

class MYHTTPClient: AFHTTPSessionManager {

    /** 单例 */
    static let shareInstance: MYHTTPClient = {
    
        let afn = MYHTTPClient()
        
        /** 设置content-Type: text/plain */
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return afn
        
    }()

    /**
     请求
     type: 请求类型
     */
    func request(type: MYHTTPClientType, URLString: String, parameters: AnyObject?, progress downloadProgress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) {
        
        if type == .GET {
            self.GET(URLString, parameters: parameters, progress: downloadProgress, success: success, failure: failure)
        } else if type == .POST {
            self.POST(URLString, parameters: parameters, progress: downloadProgress, success: success, failure: failure)
        }
    }
    
}
